<?
/*
 * scrumbrella - Scrum board.
 *
 * Copyright (C) 2009  Gustavo N. Borgoni <gborgoni@voicemedia.com.ar>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

require_once("layout_config.php");
require_once("PHPTAL.php");

include("include/permission.php");
include("include/html_utils.php");
include("include/project.php");

// Check for user logged in
$user_id = permission_redirect_user("index.php");

if ($_SERVER['REQUEST_METHOD'] == "POST") {
	$name        = $_REQUEST["project_name"];
	$role_id     = $_REQUEST["your_role"];
	$description = $_REQUEST["project_description"];
	$beginning   = $_REQUEST["project_beginning"];

	$project_id = project_create($name, $description, $beginning);
	if ($project_id > 0) {
		if ($role_id > 0) {
			permission_userproject_assign($user_id, $project_id, $role_id);
		}
	}
}

	// Load the template
	$temp = new PHPTAL('templates/project_add.xhtml');

	$temp->theme 	   = "themes/default/forms.css";
	$temp->title 	   = _("New project");
	$temp->prj_name    = _("Project name");
	$temp->yrole 	   = _("Your role");
	$temp->description = _("Description");
	$temp->user_role   = _("Role");
	$temp->user_name   = _("User name");
	$temp->dt_start	   = _("Date beggining");
	$temp->tit_user    = _("User");
	$temp->tit_role	   = _("Role");
	$temp->message_box = 1;
	$temp->message	   = _("No selected users for this project");

	$temp->roles = html_select_rolelist();

	// Error msg
	$temp->name_required = _("You must insert a project name");
	$temp->name_remote   = _("There is another project with the same name");
	$temp->role_required = _("You must select your role");
	$temp->desc_required = _("You must insert a project description");

	try 
	{
		echo $temp->execute();
	}

	catch(Exception $e)
	{
		echo $e;
	}
?>
